package com.example.blog.service;

import com.example.blog.mapper.BlogMapper;
import com.example.blog.model.BlogInfo;
import com.example.blog.model.PageRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class BlogService {

    @Autowired
    private BlogMapper blogMapper;

    public List<BlogInfo> queryBlogList(PageRequest pageRequest) {
        List<BlogInfo> blogInfos=blogMapper.queryListByPage(pageRequest);
        for (BlogInfo blogInfo : blogInfos) {
            for (int i=0;i<blogInfo.getContent().length();i++) {
                if(blogInfo.getContent().charAt(i)=='#'){
                    blogInfo.setContentfori(i,' ');
                }
            }
        }
        return blogInfos;
    }
    public BlogInfo queryBlogDetail(Integer blogId){
        return blogMapper.selectById(blogId);
    };

    public Integer publishBlog(BlogInfo blogInfo) {
        return blogMapper.insertBlog(blogInfo);
    }

    public Integer updateBlog(BlogInfo blogInfo) {
        return blogMapper.updateBlog(blogInfo);
    }
    
    public Integer queryBlogCount() {
        return blogMapper.getcount();
    }
}
